package com.zwj.controller;


import com.zwj.bo.*;
import com.zwj.entity.UserEntity;
import com.zwj.service.ClassInfoService;
import com.zwj.utils.TokenUtils;
import com.zwj.vo.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 班级信息表 前端控制器
 * </p>
 *
 * @author zwj
 * @since 2021-07-21
 */
@RestController
@RequestMapping("/class")
public class ClassInfoController {
    private final ClassInfoService classInfoService;
    public ClassInfoController(ClassInfoService classInfoService) {
        this.classInfoService = classInfoService;
    }

    @ApiOperation(value = "添加班级", notes = "添加班级")
    @PostMapping("/addClass")
    public Result addClass(@RequestBody AddClassBo addClassBo, HttpServletRequest request) {
        UserEntity userEntity = TokenUtils.getUser(request);
        return classInfoService.addClass(addClassBo,userEntity);
    }
    @ApiOperation(value = "修改班级", notes = "修改班级")
    @PostMapping("/updateClass")
    public Result updateClass(@RequestBody UpdateClassBo updateTeacherBo, HttpServletRequest request) {
        UserEntity userEntity = TokenUtils.getUser(request);
        return classInfoService.updateClass(updateTeacherBo,userEntity);
    }
    @ApiOperation(value = "查询班级", notes = "查询班级")
    @PostMapping("/selectClass")
    public Result selectClass(@RequestBody SelectClassBo selectClassBo) {
        return classInfoService.selectClass(selectClassBo,null);
    }
    @ApiOperation(value = "按ID查询班级", notes = "按ID查询班级")
    @PostMapping("/selectClassById")
    public Result selectClassById(@RequestBody SelectByIdBo selectByIdBo) {
        return classInfoService.selectClass(new SelectClassBo(),selectByIdBo.getId());
    }
    @ApiOperation(value = "添加学生", notes = "添加学生")
    @PostMapping("/addStudent")
    public Result addStudent(@RequestBody StudentBo studentBo, HttpServletRequest request) {
        UserEntity userEntity = TokenUtils.getUser(request);
        return classInfoService.addStudent(studentBo,userEntity);
    }
    @ApiOperation(value = "编辑学生", notes = "编辑学生")
    @PostMapping("/updateStudetent")
    public Result updateStudetent(@RequestBody StudentBo studentBo, HttpServletRequest request) {
        UserEntity userEntity = TokenUtils.getUser(request);
        return classInfoService.updateStudent(studentBo,userEntity);
    }
    @ApiOperation(value = "删除学生", notes = "删除学生")
    @PostMapping("/deleteStudetent")
    public Result deleteStudetent(@RequestBody StudentById studentById, HttpServletRequest request) {
        UserEntity userEntity = TokenUtils.getUser(request);
        return classInfoService.deleteStudent(studentById,userEntity);
    }
    @ApiOperation(value = "查询学生", notes = "查询学生")
    @PostMapping("/selectStudetent")
    public Result selectStudetent(@RequestBody SelectStudentBo selectStudentBo) {
        return classInfoService.selectStudent(selectStudentBo,new StudentById(),1);
    }
    @ApiOperation(value = "按ID查询学生", notes = "按ID查询学生")
    @PostMapping("/selectStudetentById")
    public Result selectStudetentById(@RequestBody StudentById studentById) {
        return classInfoService.selectStudent(new SelectStudentBo(),studentById,2);
    }
}

